package com.xiangban.exception;

import com.xiangban.model.res.ApiResult;
import com.xiangban.model.res.ApiResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    private final static Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(value = BizException.class)
    @ResponseBody
    public Object handle(Exception e){

        if( e instanceof BizException){
            BizException bizException = (BizException) e;
            return ApiResult.newErrorException(bizException.getErrorCode(),bizException.getErrorMsg());
        }else {
            return ApiResult.newErrorException(ApiResultCode.SYS_ERROR);

        }
    }

}